package com.kilman.logger.log.control;

import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;

public class DefaultLogLinesController implements LogLinesController {

    public LogLine parseLine(String rawLine, int lineNumber) {
        DefaultLogLine currentLine = new DefaultLogLine();
        currentLine.setRawLine(rawLine);
        currentLine.setLineNumber(lineNumber);
        return currentLine;
    }

    public String generateOutput(LogLines logLines) {
        List<LogLine> lines = logLines.getLines();
        
        StringBuilder sb = new StringBuilder();
        for (LogLine iLine : lines) {
            DefaultLogLine line = (DefaultLogLine)iLine;
            String escapedLine = StringEscapeUtils.escapeHtml(line.getRawLine());
            sb.append(escapedLine + "\n");
        }
        
        return sb.toString();
    }

}
